<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body onload="checkCookie()">
<script type="text/javascript">
    function setCookie(cname,cvalue,exminutes){
        var date = new Date();
        date.setMinutes(date.getMinutes()+exminutes);
        var expires = "expires="+date.toGMTString();
        document.cookie = cname+"="+cvalue+"; "+expires;
    }
    function getCookie(cname){
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) {
            var cArr=ca[i].split("=");
            if (cArr[0]==cname) { return cArr[1]; }
        }
        return "";
    }
    function checkCookie(){
        var user=getCookie("username");
        if (user!=""){
            alert("亲爱的"+ user +"，欢迎您再次访问");
        } else {
            user = prompt("请输入名字:","");
            if (user!="" && user!=null){
                setCookie("username",user,10);
            }
        }
    }
</script>
<form>

</form>
</body>
</html>